package com.etc.admin.controller;/*
 * 文件名：com.etc.admin.controller.AdminOrderController
 * 描述：后台订单管理的控制器
 * 作者：黄志鹏
 * 时间：2019/5/29 20:07
 */

import com.etc.entity.Orders;
import com.etc.service.OrderService;
import com.etc.utils.CommonMessage;
import com.etc.utils.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "admin.action")
public class AdminOrderController {

    @Autowired
    private  OrderService orderService;

    @RequestMapping("orderlist")
    @ResponseBody
    public PageData<Orders> toOrderList(Integer page, Integer limit, Model model){
        List<Orders> ordersList = orderService.listOrdersListBypage(page,limit);
        Integer count = orderService.getcount();
        PageData pageData = new PageData();
        pageData.setCode(0);
        pageData.setMsg("成功");
        pageData.setCount(count);
        pageData.setPage(page);
        pageData.setlimit(limit);
        pageData.setData(ordersList);
        return pageData;
    }

    @RequestMapping("update")
    @ResponseBody
    public CommonMessage updateOrderByOrderid(Integer orderid){
        CommonMessage commonMessage = new CommonMessage();
       boolean flag = orderService.updateOrderByOrderid(orderid);
       if (flag){
           commonMessage.setMsg("发货成功");
       }
        return commonMessage;
    }
}
